unit fmck_ProBarTemp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, fmNormal, DBGridEhGrouping, ToolCtrlsEh, DBGridEhToolCtrls,
  DynVarsEh, GridsEh, DBAxisGridsEh, DBGridEh, DB, ADODB, StdCtrls,
  Buttons, ExtCtrls;

type
  Tfrmck_ProBarTemp = class(TfrmNormal)
    adsBarcode: TADODataSet;
    dsBarcode: TDataSource;
    DBGridEh1: TDBGridEh;
    adsBarcodeOrderID: TIntegerField;
    adsBarcodeBarcode: TStringField;
    adsBarcodeNumber: TFloatField;
    adsBarcodeNumberList: TStringField;
    adsBarcodePackNo: TStringField;
    adsBarcodeSectionCount: TIntegerField;
    adsBarcodeRemark: TStringField;
    Panel1: TPanel;
    btnOK: TBitBtn;
    btnCancel: TBitBtn;
    adsBarcodeMeter: TFloatField;
    adsBarcodeYard: TFloatField;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure FormShow(Sender: TObject);
    procedure adsBarcodeNumberChange(Sender: TField);
    procedure adsBarcodeMeterChange(Sender: TField);
    procedure adsBarcodeYardChange(Sender: TField);
    procedure adsBarcodeNewRecord(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmck_ProBarTemp: Tfrmck_ProBarTemp;
  FOnChangeFlag : integer = 0;

implementation

uses dmConnect, uShare, uConst;

{$R *.dfm}

procedure Tfrmck_ProBarTemp.FormShow(Sender: TObject);
begin
  inherited;
  adsBarcode.Connection := dtmConnect.conMain;
end;

procedure Tfrmck_ProBarTemp.adsBarcodeNumberChange(Sender: TField);
begin
  inherited;
  if (adsBarCode.State in [dsInsert, dsEdit]) then
  begin
    adsBarCode.FieldByName('Weight').ReadOnly := False;
    adsBarCode.FieldByName('Weight').AsFloat := Sender.AsFloat;
  end;
end;

procedure Tfrmck_ProBarTemp.adsBarcodeMeterChange(Sender: TField);
begin
  inherited;
  if (adsBarCode.State in [dsInsert, dsEdit]) and (FOnChangeFlag=0) then
  try
    FOnChangeFlag := 1;
    adsBarCode.FieldByName('Yard').ReadOnly := False;
    adsBarCode.FieldByName('Yard').AsFloat := uShare.Round(Sender.AsFloat*0.9144, Yard_Digit);
  finally
    FOnChangeFlag := 0;
  end;
end;

procedure Tfrmck_ProBarTemp.adsBarcodeYardChange(Sender: TField);
begin
  inherited;
  if (adsBarCode.State in [dsInsert, dsEdit]) and (FOnChangeFlag=0) then
  try
    FOnChangeFlag := 1;
    adsBarCode.FieldByName('Meter').ReadOnly := False;
    adsBarCode.FieldByName('Meter').AsFloat := uShare.Round(Sender.AsFloat/0.9144, Meter_Digit);
  finally
    FOnChangeFlag := 0;
  end;
end;

procedure Tfrmck_ProBarTemp.adsBarcodeNewRecord(DataSet: TDataSet);
begin
  inherited;
  DataSet.FieldByName('OrderID').AsInteger := DataSet.RecordCount+1;
end;

end.
